package de.hpi.generator.model;

import de.hpi.generator.config.ColumnModel;

public class StringColumn extends Column {

    public StringColumn(ColumnModel aColumnModel, Table aOwner) throws Exception {
        super(aColumnModel, aOwner);
    }
    private char[] smallChars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    private char[] largeChars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
        'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    private char[] specialChars = {'.', ';', ':', '!', '#', '?', '&', ' ', '%'};
    private char[] allChars = concatenateArrays(concatenateArrays(smallChars, largeChars), specialChars);

    private char[] concatenateArrays(char[] a1, char[] a2) {
        char[] result = new char[a1.length + a2.length];
        for (int i = 0; i < a1.length; i++) {
            result[i] = a1[i];
        }
        for (int i = 0; i < a2.length; i++) {
            result[a1.length + i] = a2[i];
        }
        return result;
    }

    public String convertToString(int aNumber) throws Exception {
        String result = "";
        int charArraySize = allChars.length;
        if (aNumber < 0) {
            result += "-";
            aNumber = -aNumber;
        }
        for (int j = 0; j < aCellSize; j++) {
            int aRest = aNumber % charArraySize;
            result += allChars[aRest];
            aNumber /= allChars.length;
        }
        return result;
    }

    public String getColumnName() {
        return "String";
    }
}
